<include file="public/header" title="填写订单" body="g4"/>
<include file="public/header_nav" title="填写订单" href="javascript:void(0);" back="back"/>
<div id="wrapBody">
    <div id="pagePay">
        <form name="cart2_form" id="cart2_form" method="post">
            <input type="hidden" id="wap_invoice_title" name="invoice_title" value="个人">
            <input type="hidden" id="wap_taxpayer" name="taxpayer" value="">
            <input type="hidden" name="address_id" value="" autocomplete="off"/> <!--收货地址id-->
            <input type="hidden" name="goods_num" value="{$Request.param.goods_num}">
            <input type="hidden" name="pre_sell_id" value="{$preSell.pre_sell_id}"/>
        </form>
        <!--地址-s-->
        <div class="edit_gtfix" id="addressDefault">
            <div class="namephone fl">
                <div class="top">
                    <div class="le fl" id="default_address_consignee"></div>
                    <div class="lr fl" id="default_address_mobile"></div>
                </div>
                <div class="bot">
                    <i class="dwgp"></i>
                    <span id="default_address_text"></span>
                </div>
            </div>
            <div class="fr youjter">
                <i class="Mright"></i>
            </div>
            <div class="ttrebu">
                <img src="__STATIC__/images/tt.png"/>
            </div>
        </div>
        <!--地址-e-->
        <!--商品信息-s-->
        <div class="ord_list fill-orderlist p">
            <div class="maleri30">
                <volist name="cartList" id="cart">
                    <div class="shopprice">
                        <div class="img_or fl"><img src="{$cart[goods_id]|goods_thum_images=100,100}"/></div>
                        <div class="fon_or fl">
                            <h2 class="similar-product-text">{$cart[goods_name]}</h2>

                            <div>{$cart[spec_key_name]}</div>
                        </div>
                        <div class="price_or fr">
                            <p class="red"><span>￥</span><span>{$cart[member_goods_price]}</span></p>

                            <p class="ligfill">x{$cart[goods_num]}</p>
                        </div>
                    </div>
                </volist>
            </div>
        </div>
        <!--商品信息-e-->
        <!--配送方式 上门自提s-->
        <div class="z-select-wrap">
            <div class="z-select-title">
                <div class="maleri30">
                    选择配送方式
                </div>
            </div>
            <div class="maleri30 z-dispatching-wrap">
                <div class="p z-dispatching border-none">
                    <div class="fl">
                        快速配送
                    </div>
                    <div class="fr">
                        <label class="dispatching-checkbox" >
                            <div id="express_delivery" class="dispatching-cont z-dispatching-cheng"></div>
                        </label>
                    </div>
                </div>
                <div class="z-dispatching-one dispatching-font1" style="display: block;">
                    工作日、双休日与节假日均可送货
                </div>
            </div>
        </div>
        <!--配送方式 上门自提e-->
        <!--支持配送,发票信息-s-->
        <div class="information_dr">
            <div class="maleri30">
                <div class="invoice list7">
                    <div class="myorder p">
                        <div class="content30">
                            <a class="invoiceclickin" href="javascript:void(0)">
                                <div class="order">
                                    <div class="fl">
                                        <span>发票信息</span>
                                    </div>
                                    <div class="fr">
                                        <span class="invoice_title" style="margin-top: 0.6rem;">不开发票</span>
                                        <i class="Mright"></i>
                                    </div>
                                </div>
                            </a>
                        </div>
                    </div>
                </div>
                <div id="invoice" class="invoice list7" style="display: none;">
                    <div class="myorder p">
                        <div class="content30">
                            <div class="incorise" id="invoice_radio_title">
                                <span>发票抬头：</span>

                                <div class="myorder radios-choice-h">
                                    <div class="incorise">
                                        <label><input type="radio" class="alonestyle" value="个人" name="radio_title"
                                                      data="geren" id="geren">个人</label>
                                        <label><input type="radio" class="alonestyle" value="单位" name="radio_title"
                                                      data="danwei" id="danwei">单位</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="myorder p" id="monad">
                        <div class="incorise">
                            <input type="text" id="invoice_title" value="" placeholder="请填写单位名称"/>
                            <input type="text" id="taxpayer" value="" placeholder="请在此填写纳税人识别号"/>
                        </div>
                        <span style="display: block; color:red;font-size:.512rem;line-height: .64rem; ">开单位抬头发票，请准确填写对应的“纳税人识别号”，以免影响您的发票报销.</span>
                    </div>


                    <div class="myorder p">
                        <div class="content30">
                            <div class="incorise">
                                <span>发票内容：</span>

                                <div class="myorder radios-choice-h" id="noincorise">
                                    <div class="incorise">
                                        <label><input type="radio" class="alonestyle" value="不开发票" name="radio_cont"
                                                      data="noincorise" id="noincorises">不开发票</label>
                                        <label><input type="radio" class="alonestyle" value="明细" name="radio_cont"
                                                      data="detail" id="detail">明细</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="myorder p">
                        <div class="content30">
                            <div class="incorise">
                                <div class="myorder p">
                                    <div class="content30">
                                        <div class="incorise">
                                            <a href="javascript:void(0)" onclick="save_invoice()"
                                               class="submits_de bagrr phoneclck">确认</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--支持配送,发票信息-s-->
        <!--卖家留言-s-->
        <div class="customer-messa">
            <div class="maleri30">
                <p>用户备注（50字）</p>
                <textarea class="tapassa" id="user_note" maxlength="50" placeholder="选填"></textarea>
                <span class="xianzd"><em id="zero">50</em>/50</span>
            </div>
        </div>
        <!--卖家留言-e-->
        <!--订单金额-s-->
        <div class="information_dr ">
            <div class="z-monry">
                <div class="maleri30">
                    <div class="p z-monry-cont deposit_div" style="display: none">
                        <div class="fl">
                            尾款
                        </div>
                        <div class="fr">
                            <a> ￥<span id="balance_price">0.00</span>元</a>
                        </div>
                    </div>
                    <div class="p z-monry-cont">
                        <div class="fl">
                            <if condition="$preSell['deposit_price'] gt 0">订金<else/>商品金额</if>
                        </div>
                        <div class="fr">
                            <a> ￥<span>{$cartTotalPrice|number_format=2}</span>元</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--订单金额 -e-->
        <!--提交订单-s-->
        <div class="mask-filter-div" style="display: none;"></div>
        <div class="payit fillpay ma-to-20">
            <div class="fr submit_price">
                <a href="javascript:void(0)" onclick="submit_order()">提交订单</a>
            </div>
            <div class="fl">
                <p><span class="pmo">应付金额：</span>￥<span id="payables">0</span><span></span></p>
            </div>
        </div>
        <!--提交订单-e-->
    </div>
    <div id="addressList" style="display: none">
        <!--地址-s-->
        <div class="dizhi-pop">
            <div class="z-Package-hrader">
                <i class="z-Package-icon Package-icon-close" id="address_list_back"></i>
                <h5>选择地址</h5>
            </div>
            <div id="address_list_html" style="height: 19.5rem;overflow:  scroll;"></div>
            <!--地址-e-->
            <div class="createnew ">
                <a id="add_address" >+新建地址</a>
            </div>
        </div>
    </div>
    <div id="addressAdd" style="display: none">
        <div class="dizhi-pop">
            <div class="z-Package-hrader">
                <i class="z-Package-icon Package-icon-close" id="address_add_back"></i>
                <h5>新建/编辑地址</h5>
            </div>
            <div class="floor my p edit">
                <form id="address_form">
                    <input type="hidden" value="" name="address_id"/>
                    <input type="hidden" value="" name="province"/>
                    <input type="hidden" value="" name="city"/>
                    <input type="hidden" value="" name="district"/>

                    <div class="content">
                        <div class="floor list7">
                            <div class="myorder p">
                                <div class="content30">
                                    <a href="javascript:void(0)">
                                        <div class="order">
                                            <div class="fl">
                                                <span>收货人:</span>
                                            </div>
                                            <div class="fl">
                                                <input type="text" value="" name="consignee"/>
                                                <span class="err" id="err_address_consignee"></span>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <div class="myorder p">
                                <div class="content30">
                                    <a href="javascript:void(0)">
                                        <div class="order">
                                            <div class="fl">
                                                <span>手机号码:</span>
                                            </div>
                                            <div class="fl">
                                                <input type="tel" value="" name="mobile" onkeyup="this.value=this.value.replace(/[^\d]/g,'')"/>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <div class="myorder p">
                                <div class="content30">
                                    <a href="javascript:void(0)" onclick="location_address(this);">
                                        <div class="order">
                                            <div class="fl">
                                                <span>所在地区: </span>
                                            </div>
                                            <div class="fl">
                                                <span id="area"></span>
                                            </div>
                                            <div class="fr">
                                                <i class="Mright"></i>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <div class="myorder p">
                                <div class="content30">
                                    <a href="javascript:void(0)">
                                        <div class="order">
                                            <div class="fl">
                                                <span>详细地址:</span>
                                            </div>
                                            <div class="fl">
                                                <input type="text" value="" name="address"/>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="createnew ">
                        <a id="address_form_confirm">确认</a>
                    </div>
                </form>
            </div>
            <!--选择地区-s-->
            <div class="container">
                <div class="city">
                    <div class="screen_wi_loc">
                        <div class="classreturn loginsignup">
                            <div class="content">
                                <div class="ds-in-bl return seac_retu">
                                    <a href="javascript:void(0);" onclick="close_location();"><img src="__STATIC__/images/return.png" alt="返回"></a>
                                </div>
                                <div class="ds-in-bl search center">
                                    <span class="sx_jsxz">选择地区</span>
                                </div>
                                <div class="ds-in-bl suce_ok">
                                    <a href="javascript:void(0);">&nbsp;</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="province-list"></div>
                    <div class="city-list" style="display:none"></div>
                    <div class="area-list" style="display:none"></div>
                </div>
            </div>
            <!--选择地区-e-->
        </div>
        <script src="__STATIC__/js/mobile-location.js"></script>
        <script>
            //选择地址回调
            var address_form = $('#address_form');
            function select_area_callback(province_name, city_name, district_name, province_id, city_id, district_id) {
                var area = province_name + ' ' + city_name + ' ' + district_name;
                $("#area").text(area);
                address_form.find("input[name='province']").val(getCookie('province_id'));
                address_form.find("input[name='city']").val(getCookie('city_id'));
                address_form.find("input[name='district']").val(getCookie('district_id'));
            }
        </script>
    </div>
</div>
<script type="text/javascript">
    var cart2_form = $('#cart2_form');
    window.addEventListener('popstate', function () {
        panel();
    });
    $(document).ready(function () {
        get_address_list();
    });
    //各种弹窗返回上一步
    $(function () {
        //主页面返回上一步
        $(document).on('click', '#back', function () {
            var goods_id = cart2_form.find("input[name='goods_id']");
            var item_id = cart2_form.find("input[name='item_id']");
            window.location.href = "/index.php?m=Mobile&c=Goods&a=goodsInfo&id="+goods_id.val()+'&item_id='+item_id.val();
        });
        //地址弹窗返回上一步
        $(document).on('click', '#address_list_back,#address_add_back,#shop_list_back,#shop_consignee_back,#map_back', function () {
            history.back(-1);
            panel();
        });
    })
    //点击地址
    $(function () {
        //点击地址
        $(document).on('click', '#addressDefault', function () {
            window.location.hash = "#addressList";
            get_address_list();
            panel();
        });
        //选择地址
        $(document).on('click', '.select_address', function () {
            var address_id = $(this).data('address-id');
            var mobile = $(this).data('mobile');
            var consignee = $(this).data('consignee');
            var address_area = $(this).data('address-area');
            var address = $(this).data('address');
            var longitude = $(this).data('longitude');
            var latitude = $(this).data('latitude');
            cart2_form.find("input[name='address_id']").val(address_id);
            $("#default_address_mobile").empty().html(mobile);
            $("#default_address_consignee").empty().html(consignee);
            $("#default_address_text").empty().html(address_area + ' '+ address);
            window.location.hash = "#";
            panel();
            ajax_order_price();
        });
        //点击新建地址
        $(document).on('click', '#add_address', function () {
            address_form.find("input[name='address_id']").val('');
            address_form.find("input[name='consignee']").val('');
            address_form.find("input[name='address']").val('');
            address_form.find("input[name='mobile']").val('');
            address_form.find("input[name='province']").val('');
            address_form.find("input[name='city']").val('');
            address_form.find("input[name='district']").val('');
            $('#area').html('');
            window.location.hash = "#addressAdd";
            panel();
        });
        //添加地址
        $(document).on('click', '#address_form_confirm', function () {
            $.ajax({
                type: "POST",
                url: '/index.php?m=Mobile&c=User&a=addressSave',
                data:  $("#address_form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.status == 1) {
                        $("#address_add_back").trigger('click');
                        get_address_list(data.result.address_id);
                    } else {
                        var err_msg = data.msg;
                        $.each(data.result, function (index, item) {
                            err_msg = item;
                        });
                        layer.open({icon: 2, content: err_msg, time: 2});
                    }
                }
            });
        });
        //编辑地址弹窗事件
        $(document).on("click", '.address_item', function (e) {
            window.location.hash = "#addressAdd";
            panel();
            var select_address = $(this).parent().parent().find('.select_address');
            address_form.find("input[name='address_id']").val(select_address.data('address-id'));
            address_form.find("input[name='consignee']").val(select_address.data('consignee'));
            address_form.find("input[name='address']").val(select_address.data('address'));
            address_form.find("input[name='mobile']").val(select_address.data('mobile'));
            address_form.find("input[name='province']").val(select_address.data('province-id'));
            address_form.find("input[name='city']").val(select_address.data('city-id'));
            address_form.find("input[name='district']").val(select_address.data('district-id'));
            $('#area').html(select_address.data('address-area'));
        })
    })
    //单页面显示
    function panel(){
        var hash = window.location.hash;
        $('#wrapBody').children('div').hide();
        if(hash == ''){
            $('#pagePay').show();
        }else{
            $(hash).show();
        }
    }
    //获取地址列表
    function get_address_list(select_address_id){
        var address_id = cart2_form.find("input[name='address_id']");
        $.ajax({
            type: "get",
            url: '/index.php?m=Mobile&c=User&a=ajaxAddressList',
            dataType: "json",
            success: function (data) {
                var address_list_html = '';
                for (var i = 0; i < data.length; i++) {
                    address_list_html += '<div class="jd_listaddless p "> <div class="maleri30"> <a class="select_address address_id_'+data[i].address_id+'" ' +
                            'data-address-id="'+data[i].address_id+'" data-mobile="'+ data[i].mobile +'" data-consignee="'+ data[i].consignee+'" ' +
                            'data-address-area="'+ data[i].address_area+'" data-address="'+ data[i].address+'" data-province-id="'+data[i].province+'"  ' +
                            'data-city-id="'+data[i].city+'" data-district-id="'+data[i].district+'" data-town-id="'+data[i].twon+'" data-longitude="'+data[i].longitude+'" ' +
                            'data-latitude="'+data[i].latitude+'"  > <div class="name fl"> <h1>'+data[i].consignee+'</h1> </div> <div class="numberaddress fl"> ' +
                            '<span class="number"><i class="number-dh">电话：</i>'+ data[i].mobile +'</span> <span class="similars">' + data[i].address_area + ' ' + data[i].address +'</span> ' +
                            '</div> </a> <div class="editdiv fl"> <a class="address_item"> <i class="eedit"></i> </a> </div> </div> </div>';
                }
                $("#address_list_html").empty().html(address_list_html);
                if(data.length == 0){
                    $("#add_address").trigger('click');
                }
                if(data.length > 0 && address_id.val() == ''){
                    $("#address_list_html").find('.select_address').eq(0).trigger('click');
                }
                if(select_address_id > 0){
                    $("#address_list_html").find('.address_id_'+select_address_id).trigger('click');
                }
            }
        });
    }
    function close_location(){
        var province_div = $('.province-list');
        var city_div = $('.city-list');
        var area_div = $('.area-list');
        if(area_div.is(":hidden") == false){
            area_div.hide();
            city_div.show();
            province_div.hide();
            return;
        }
        if(city_div.is(":hidden") == false){
            area_div.hide();
            city_div.hide();
            province_div.show();
            return;
        }
        if(province_div.is(":hidden") == false){
            area_div.hide();
            city_div.hide();
            $('.container').animate({width: '0', opacity: 'show'}, 'normal',function(){
                $('.container').hide();
            });
            undercover();
            $('.mask-filter-div').css('z-index','inherit');
            return;
        }
    }
    function location_address(e){
        $('.container').animate({width: '14.4rem', opacity: 'show'}, 'normal',function(){
            $('.container').show();
        });
        if(!$('.container').is(":hidden")){
            $('body').css('overflow','hidden')
            cover();
            $('.mask-filter-div').css('z-index','9999');
        }
    }
    function toogle(id) {
        condition = $(id).attr('data');
        //个人
        if (condition == 'geren') {
            $('#wap_invoice_title').val("个人");
            $('#monad').hide();
        }
        //单位
        if (condition == 'danwei') {
            invoice_title = $('#invoice_title').val();
            $('#wap_invoice_title').val(invoice_title);
            $('#monad').show();
        }

        invoice_title = $(id).find('input').attr('value');
        //不开发票
        if (condition == 'noincorise') {
            $('#wap_invoice_title').val("");
//                $('#monad,#invoice').hide();
//                $(".invoice_title").html("不开发票");
        }
        $("input[type='radio']").each(function () {
            if ($(this).is(":checked")) {
                if ($(this).val() == "个人") {
                    invoice_title = "个人";
                    taxpayer = "";
                    str = "个人";
                }
                if ($(this).val() == '不开发票') {
                    invoice_title = "";
                    taxpayer = "";
                    invoice_desc = '不开发票';
                    str = "不开发票";
                    $('#monad').hide();
                }
                if ($(this).val() == "单位") {
                    invoice_title = $("#invoice_title").val();
                    taxpayer = $("#taxpayer").val();
                    $('#monad').show();
                    str = "单位";
                }
                if ($(this).val() == '明细') {
                    invoice_desc = "明细";
                }
            }
        });
        if ($("#detail").is(":checked")) {
            str += " - 明细";
        }
        if (str == "不开发票") {
            $('#wap_invoice_title').val("");
            $(".invoice_title").html(str);
        } else {
            $('#wap_invoice_title').val(invoice_title);
            $(".invoice_title").html("纸质（" + str + "）");
        }
    }
    $(document).on("click", "input[name='radio_cont']", function () {
        toogle(this);
    });
    function save_invoice() {
        var str = "";
        var invoice_title;
        var taxpayer;
        var invoice_desc;
        var res = "y";
        $("input[name='radio_cont']").each(function () {
            if ($(this).is(":checked")) {
                if ($(this).val() == "个人") {
                    invoice_title = "个人";
                    taxpayer = "";
                    str = "个人";
                }
                if ($(this).val() == '不开发票') {
                    invoice_title = "个人";
                    taxpayer = "";
                    invoice_desc = '不开发票';
                    str = "不开发票";
                }
                if ($(this).val() == "单位") {
                    if (!$("#noincorises").is(":checked")) {
                        if ($("#invoice_title").val() == "") {
                            layer.open({content: '请输入单位名称', time: 2});
                            res = "n";
                            return false;
                        }
                        taxpayer = $("#taxpayer").val();
//                                    if (taxpayer != "") {
                        if ((taxpayer.length == 15) || (taxpayer.length == 18) || (taxpayer.length == 20)) {
                        } else {
                            layer.open({content: "请输入正确的纳税人识别号！(核对位数)", time: 2});
                            res = "n";
                            return false;
                        }
                        var addressCode = taxpayer.substring(0, 6);
                        // 校验地址码
                        var check = checkAddressCode(addressCode);
                        if (!check) {
                            layer.open({content: "请输入正确的纳税人识别号(地址码)！", time: 2});
                            res = "n";
                            return false;
                        }
                        // 校验组织机构代码
                        var orgCode = taxpayer.substring(6, 9);
                        check = orgcodevalidate(orgCode);
                        if (!check) {
                            layer.open({content: "请输入正确的纳税人识别号(组织机构代码) ！", time: 2});
                            res = "n";
                            return false;
                        }
                        $('#wap_taxpayer').val(taxpayer);
//                                    }
                        invoice_title = $("#invoice_title").val();
                        taxpayer = $("#taxpayer").val();
                        str = $("#invoice_title").val();
                    }
                }
                if ($(this).val() == '明细') {
                    invoice_desc = "明细";
                }
            }
        });
        if ($("#detail").is(":checked")) {
            str += " - 明细";
        }
        if (str == "不开发票") {
            $('#wap_invoice_title').val("");
            $('#wap_taxpayer').val("");
            $(".invoice_title").html(str);
        } else {
            $('#wap_taxpayer').val(taxpayer);
            $('#wap_invoice_title').val(invoice_title);
            $(".invoice_title").html("纸质（" + str + "）");
        }

        if (res != "n") {
            var data = {invoice_title: invoice_title, taxpayer: taxpayer, invoice_desc: invoice_desc};
            $.post("{:U('Cart/save_invoice')}", data, function (json) {
                var data = eval("(" + json + ")");

                $("#invoice").hide()
            });
        }

    }
    function get_invoice() {
        var str = "";
        $.get("{:U('Cart/invoice')}", function (json) {
            var data = eval("(" + json + ")");
            if (data.status > 0) {

                if (data.result.invoice_title == "") {
                    $('#monad').hide();

                } else {
                    $('#wap_invoice_title').val(data.result.invoice_title);
                    $('#wap_taxpayer').val(data.result.taxpayer);
                    $('#invoice_title').val(data.result.invoice_title);
                    $("#invoice_desc").val(data.result.invoice_desc);
                    $("#taxpayer").val(data.result.taxpayer);
                    str = "纸质（" + data.result.invoice_title + "-明细）";
                    $("#danwei").attr("checked", "checked");
                }
                if (data.result.invoice_title == "个人") {
                    $('#wap_invoice_title').val("个人");
                    $('#wap_taxpayer').val("");
                    $("#geren").attr("checked", "checked");
                    $('#invoice_title').val("");
                    $("#invoice_desc").val("");
                    $("#taxpayer").val("");
                    $('#monad').hide();
                    $(".invoice_title").html("纸质（个人-明细）");
                    str = "纸质（个人-明细）";
                }
                if (data.result.invoice_desc == "不开发票") {
                    $('#wap_invoice_title').val("");
                    $('#wap_taxpayer').val("");
                    $('#invoice_title').val("");
                    $("#invoice_desc").val(data.result.invoice_desc);
                    $("#taxpayer").val("");
                    $("#noincorises").attr("checked", "checked");
                    str = "不开发票";
                } else {
//                        $('#monad,#invoice').show();
                    $("#detail").attr("checked", "checked");
                }
                $(".invoice_title").html(str);

            } else {
                $("#geren").attr("checked", "checked");
                $('#monad').hide();
                $("#noincorises").attr("checked", "checked");
            }
        });
    }
    //备注
    $(function () {
        //备注输入
        $(document).on('keyup', '#user_note', function () {
            $('input[name="user_note"]').val(this.value);
            var len = this.value.length;
            var limit = 50;
            if(len > limit){
                $(this).val($(this).val().substring(0,limit));
            }
            var num = limit - len;
            if(num <= 0){
                $("#zero").text(0);
            }else{
                $("#zero").text(num);
            }
        });
    })
    // 获取订单价格
    function ajax_order_price() {
        var address_id = cart2_form.find("input[name='address_id']").val();
        if(address_id == ''){
            get_address_list();
        }
        $.ajax({
            type: "POST",
            url: '/index.php?m=Home&c=Cart&a=pre_sell_place',
            data: cart2_form.serialize(),
            dataType: "json",
            success: function (data) {
                if (data.status != 1) {
                    layer.open({icon: 2, content: data.msg, time: 1, end:function(){
                        // 登录超时
                        if (data.status == -100) {
                            location.href = "{:U('Mobile/User/login')}";
                        }
                        $('.submit_price a').addClass("disable");
                    }});
                    return false;
                }else{
                    $('.submit_price a').removeClass("disable");
                    refresh_price(data);
                }
            }
        });
    }
    //刷新价格
    function refresh_price(data) {
        if(data.result.deposit_price > 0){
            $('.deposit_div').show();
            $('#balance_price').text(data.result.balance_price.toFixed(2));
        }
        if(typeof(data.result.order_amount) != 'undefined'){
            $("#payables").text(data.result.order_amount.toFixed(2));// 应付
        }
    }
    // 提交订单
    var ajax_return_status = 1; // 标识ajax 请求是否已经回来 可以进行下一次请求
    function submit_order() {
        if ($('.submit_price a').hasClass("disable")) {
            return;
        }
        if (ajax_return_status == 0){
            return false;
        }
        ajax_return_status = 0;
        $.ajax({
            type: "POST",
            url: "{:U('Home/Cart/pre_sell_place')}",//+tab,
            data: cart2_form.serialize() + "&act=submit_order",// 你的formid
            dataType: "json",
            success: function (data) {
                layer.closeAll();
                if (data.status != 1) {
                    showErrorMsg(data.msg);  //执行有误
                    // 登录超时
                    if (data.status == -100){
                        location.href = "{:U('Mobile/User/login')}";
                    }
                    ajax_return_status = 1; // 上一次ajax 已经返回, 可以进行下一次 ajax请求
                    return false;
                }
                $("#postFee").text(data.result.shipping_price); // 物流费
                if (data.result.coupon_price == null) {
                    $("#couponFee").text(0);// 优惠券
                } else {
                    $("#couponFee").text(data.result.coupon_price);// 优惠券
                }
                $("#balance").text(data.result.user_money);// 余额
                $("#pointsFee").text(data.result.integral_money);// 积分支付
                $("#payables").text(data.result.order_amount);// 应付
                $("#order_prom_amount").text(data.result.order_prom_amount);// 订单 优惠活动
                showErrorMsg('订单提交成功，跳转支付页面!');
                location.href = "/index.php?m=Mobile&c=Cart&a=cart4&order_sn=" + data.result;
            }
        });
    }
    $(function () {
        get_invoice();
        $('.submits_de').click(function () {
            $('.mask-filter-div').hide();
            $('.losepay').hide();
        })

        //显示隐藏使用发票信息
        $('.invoiceclickin').click(function () {
            get_invoice();
            $('#invoice').toggle(300);
        })
    })
</script>
</body>
</html>
